import { defineStore } from 'pinia';
import * as shoppingCartApi from '@/api/shopping-cart';

export const useShoppingCartStore = defineStore('shoppingCart', () => {
	async function getShoppingCart(param?: any) {
		uni.showLoading();
		const response = await shoppingCartApi.getShoppingCart(param);
		uni.hideLoading();
		if (response.code === 20000) {
			return response.data.shoppingCart;
		}
		return {};
	}

	async function updateQuantity(param?: any) {
		uni.showLoading();
		await shoppingCartApi.updateQuantity(param);
		uni.hideLoading();
	}

	async function deleteProducts(param?: any) {
		uni.showLoading();
		await shoppingCartApi.deleteProducts(param);
		uni.hideLoading();
	}

	async function addProducts(param?: any) {
		uni.showLoading();
		await shoppingCartApi.addProducts(param);
		uni.hideLoading();
	}

	return {
		getShoppingCart,
		updateQuantity,
		deleteProducts,
		addProducts
	};
});
